//
//  HP_LoanHeaderView.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/8/31.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "HP_LoanHeaderView.h"
#import "Mediator+Loan.h"
#import "HomePageViewController.h"

@implementation HP_LoanHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initialize];
    }
    return self;
}

-(void)applyBtnAction{
    
    UIViewController *vc = [[Mediator sharedInstance] Loan_applyViewController:@"id"];
    HomePageViewController *homeVC = (HomePageViewController *)self.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder.nextResponder;
    [homeVC.navigationController pushViewController:vc animated:YES];
    
}

-(void)initialize{
    
    UIView *backView = [[UIView alloc]init];
    backView.layer.masksToBounds = YES;
    backView.layer.cornerRadius = 4;
    backView.frame = CGRectMake(12, 5, ScreenWidthMao-24, 150*ScreenWidthMao/375.f-12);
    [self addSubview:backView];
    
    CAGradientLayer *caLayer = [CAGradientLayer layer];
    caLayer.frame = backView.bounds;
    caLayer.startPoint = CGPointMake(0, 0);
    caLayer.endPoint = CGPointMake(1, 0);
    //设置颜色数组
    caLayer.colors = @[(__bridge id)HexColor(0xE4D1AD).CGColor,
                       (__bridge id)HexColor(0xBEA471).CGColor];
    
    //设置颜色分割点（范围：0-1）
    caLayer.locations = @[@(0.0f), @(1.0f)];
    [backView.layer addSublayer:caLayer];
    
    
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.text = @"可贷额度";
    _titleLabel.textColor = HexColor(0xFFFFFF);
    _titleLabel.alpha = 0.7;
    _titleLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(backView.mas_left).offset(15);
        make.top.mas_equalTo(backView.mas_top).offset(28);
        make.height.mas_offset(@18);
    }];
    
    _moneyLabel = [[UILabel alloc]init];
    _moneyLabel.textColor = HexColor(0xFFFFFF);
    _moneyLabel.font = UIFontBoldCustom(32);
    _moneyLabel.text = @"0.00";
    [self addSubview:_moneyLabel];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8);
        make.height.mas_offset(@37);
    }];
    
    
    _tipLabel = [[UILabel alloc]init];
    _tipLabel.textColor = HexColor(0xFFFFFF);
    _tipLabel.text = @"极速审批|超低利率|极速到账";
    _tipLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_tipLabel];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        if (ScreenWidthMao <375) {
            make.bottom.mas_equalTo(backView.mas_bottom).offset(-13);
        }else{
            make.bottom.mas_equalTo(backView.mas_bottom).offset(-28);
        }
        
        make.left.mas_equalTo(self.titleLabel);
    }];
    
    _applyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_applyBtn setTitle:@"立即申请" forState:UIControlStateNormal];
    [_applyBtn setBackgroundColor:[UIColor whiteColor]];
    [_applyBtn setTitleColor:ThemeMaoColor forState:UIControlStateNormal];
    _applyBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    _applyBtn.layer.masksToBounds = YES;
    _applyBtn.layer.cornerRadius = 15;
    [_applyBtn addTarget:self action:@selector(applyBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_applyBtn];
    [_applyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(backView.mas_right).offset(-15);
        make.centerY.mas_equalTo(backView);
        make.width.mas_offset(@90);
        make.height.mas_offset(@30);
    }];
    
    
}

@end
